Socket
Socket
Sign inDemoInstall

@hapi/subtext

Package Overview
Dependencies
Maintainers
7
Versions
13
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@hapi/subtext

HTTP payload parsing


Version published
Weekly downloads
865K
increased by5.7%
Maintainers
7
Weekly downloads
 
Created

What is @hapi/subtext?

@hapi/subtext is a module for parsing request payloads in Hapi.js applications. It supports various content types including JSON, form data, and multipart data. It is designed to handle large payloads efficiently and provides a simple API for extracting and processing request data.

What are @hapi/subtext's main functionalities?

Parsing JSON Payloads

This code demonstrates how to use @hapi/subtext to parse JSON payloads from incoming HTTP requests. The `Subtext.parse` method is used to extract and parse the payload, which is then sent back in the response.

const Subtext = require('@hapi/subtext');
const Http = require('http');

const server = Http.createServer(async (req, res) => {
  const { payload } = await Subtext.parse(req, null, { parse: true, output: 'data' });
  res.end(`Received JSON: ${JSON.stringify(payload)}`);
});

server.listen(3000, () => {
  console.log('Server running at http://localhost:3000/');
});

Parsing Form Data

This example shows how to parse form data using @hapi/subtext. The `Subtext.parse` method is used similarly to the JSON example, but it can handle form-encoded data as well.

const Subtext = require('@hapi/subtext');
const Http = require('http');

const server = Http.createServer(async (req, res) => {
  const { payload } = await Subtext.parse(req, null, { parse: true, output: 'data' });
  res.end(`Received Form Data: ${JSON.stringify(payload)}`);
});

server.listen(3000, () => {
  console.log('Server running at http://localhost:3000/');
});

Handling Multipart Data

This code demonstrates how to handle multipart data using @hapi/subtext. The `Subtext.parse` method is configured to output a stream, which is suitable for handling large multipart payloads.

const Subtext = require('@hapi/subtext');
const Http = require('http');

const server = Http.createServer(async (req, res) => {
  const { payload } = await Subtext.parse(req, null, { parse: true, output: 'stream' });
  res.end('Received Multipart Data');
});

server.listen(3000, () => {
  console.log('Server running at http://localhost:3000/');
});

Other packages similar to @hapi/subtext

Keywords

FAQs

Package last updated on 14 Feb 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc